/*
 * Powered By [rapid-framework]
 * Web Site: http://www.rapid-framework.org.cn
 * Google Code: http://code.google.com/p/rapid-framework/
 * Since 2008 - 2010
 */

package com.hibernate.model;

import java.util.Date;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.Table;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;
import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.hibernate.annotations.GenericGenerator;
import org.hibernate.javacommon.base.BaseEntity;
import org.hibernate.validator.constraints.Length;
import org.hibernate.validator.constraints.NotBlank;

/**
 * 日志表
 * 
 * @author shewei.deng bo.liu
 * @version 1.0
 * @since 1.0
 */
@Entity
@Table(name = "OPERATION_LOG")
public class OperationLog extends BaseEntity implements java.io.Serializable {

	private static final long serialVersionUID = 5454155825314635348L;
	//date formats
	public static final String FORMAT_DATE = DATE_FORMAT;

	@NotBlank
	private long id;
	@Length(max = 40)
	private String pyId;
	private long operatorId;
	private Date logTimeStamp;
	@Length(max = 100)
	private String type;
	@Length(max = 2000)
	private String logDesc;
	@Length(max = 1000)
	private String result;
	@Length(max = 200)
	private String ip;
	@Length(max = 2000)
	private String userAgent;
	@Length(max = 100)
	private String operatorName;
	@Length(max = 100)
	private String target;
	private long targetId;
	@Length(max = 100)
	private String targetName;
	

	public OperationLog() {

	}

	public OperationLog(long id) {
		this.id = id;
	}

	
	@Id
	@GeneratedValue(generator = "logIdGenerator")
	@GenericGenerator(name = "logIdGenerator", strategy = "native")
	@Column(name = "ID", unique = true, nullable = false, insertable = true, updatable = true)
	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	@Column(name = "PYID", unique = false, insertable = true, updatable = true, length = 40)
	public String getPyId() {
		return pyId;
	}

	public void setPyId(String pyId) {
		this.pyId = pyId;
	}

	@Column(name = "OPERATOR_ID", unique = false, insertable = true, updatable = true)
	public long getOperatorId() {
		return operatorId;
	}

	public void setOperatorId(long operatorId) {
		this.operatorId = operatorId;
	}

	@Column(name = "LOGTIMESTAMP", unique = false, insertable = true, updatable = true)
	public Date getLogTimeStamp() {
		return logTimeStamp;
	}

	public void setLogTimeStamp(Date logTimeStamp) {
		this.logTimeStamp = logTimeStamp;
	}

	@Column(name = "TYPE", unique = false, insertable = true, updatable = true, length = 10)
	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	@Column(name = "LOGDESC", unique = false, insertable = true, updatable = true, length = 200)
	public String getLogDesc() {
		return logDesc;
	}

	public void setLogDesc(String logDesc) {
		this.logDesc = logDesc;
	}

	@Column(name = "RESULT", unique = false, insertable = true, updatable = true, length = 10)
	public String getResult() {
		return result;
	}

	public void setResult(String result) {
		this.result = result;
	}

	@Column(name = "IP", unique = false, insertable = true, updatable = true, length = 20)
	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	@Column(name = "USER_AGENT", unique = false, insertable = true, updatable = true, length = 255)
	public String getUserAgent() {
		return userAgent;
	}

	public void setUserAgent(String userAgent) {
		this.userAgent = userAgent;
	}

	@Column(name = "OPERATOR_NAME", unique = false, insertable = true, updatable = true, length = 50)
	public String getOperatorName() {
		return operatorName;
	}

	public void setOperatorName(String operatorName) {
		this.operatorName = operatorName;
	}

	@Column(name = "TARGET", unique = false, insertable = true, updatable = true, length = 50)
	public String getTarget() {
		return target;
	}

	public void setTarget(String target) {
		this.target = target;
	}

	@Column(name = "TARGET_ID", unique = false, insertable = true, updatable = true)
	public Long getTargetId() {
		return targetId;
	}

	public void setTargetId(long targetId) {
		this.targetId = targetId;
	}

	@Column(name = "TARGET_NAME", unique = false, insertable = true, updatable = true, length = 50)
	public String getTargetName() {
		return targetName;
	}
	public void setTargetName(String targetName) {
		this.targetName = targetName;
	}
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
				.append("Id", getId()).append("Pyid", getPyId())
				.append("OperatorId", getOperatorId())
				.append("LogTimeStamp", getLogTimeStamp()).append("Type", getType())
				.append("LogDesc", getLogDesc()).append("Result", getResult())
				.append("Ip", getIp()).append("UserAgent", getUserAgent())
				.append("OperatorName", getOperatorName())
				.append("Target", getTarget())
				.append("TargetId", getTargetId()).toString();
	}

	public int hashCode() {
		return new HashCodeBuilder().append(getId()).toHashCode();
	}

	public boolean equals(Object obj) {
		if (obj instanceof OperationLog == false)
			return false;
		if (this == obj)
			return true;
		OperationLog other = (OperationLog) obj;
		return new EqualsBuilder().append(getId(), other.getId()).isEquals();
	}
	

}
